package com.estate.service.controller;

import com.estate.bean.Repair;
import com.estate.service.service.RepairService;
import com.estate.util.JsonResult;
import com.estate.util.ResultTool;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/repair")
public class RepairController {
    @Resource
    private RepairService repairService;

    @GetMapping("/list/{page}/{size}")
    public JsonResult list(@PathVariable("page") int page, @PathVariable("size") int size) {
        log.info("page:{},size:{}", page, size);
        JsonResult result = repairService.listByPage(page, size);
        log.info("result:{}", result);
        return result;
    }

    @PostMapping("/save")
    public JsonResult save(Repair repair) {
        log.info("新增repair:{}", repair);
        JsonResult result = repairService.saveRepair(repair);
        log.info("result:{}", result);
        return result;
    }

    @DeleteMapping("/delete")
    public JsonResult delete(@RequestParam("repairId") String repairId) {
        log.info("删除的repairId:{}", repairId);
        JsonResult result = repairService.deleteRepair(repairId);
        log.info("result:{}", result);
        return result;
    }

    @PutMapping("/update")
    public JsonResult update(Repair repair) {
        log.info("修改repair数据:{}", repair);
        JsonResult result = repairService.updateRepair(repair);
        log.info("result:{}", result);
        return result;
    }

    @GetMapping("/list/{repairId}")
    public JsonResult list(@PathVariable("repairId") String repairId){
        log.info("repairId:{}", repairId);
        JsonResult result = ResultTool.success(repairService.getById(repairId));
        log.info("result:{}", result);
        return result;
    }
}
